<template>
    <div class="login-container">
        <div class="title">
            <span>欢迎登录随行笔记</span>
        </div>
        <div class="username">
            <label for="username">用户名</label>
            <input type="text" id="username" v-model="username">
        </div>
        <div class="password">
            <label for="password">密 码</label>
            <input type="password" id="password" v-model="password">
            <span class="icon">o</span>
        </div>
        <div class="btn">
            <label>忘记密码</label>
            <div class="button" @click="loginClick">登录</div>
        </div>
    </div>
</template>
<script>
import { userLogin } from '@/api/user';
import obtainToken from '@/util/obtainToken';
import md5 from 'md5';
export default {
    data(){
        return{
            username:'',
            password:''
        }
    },
    methods:{
        loginClick(){
            console.log(this.username,this.password);
            userLogin(this.username,this.password).then((result)=>{
                if(result){
                    // 把token设置到localStorage里面
                    // localStorage.setItem();
                    let token = obtainToken(document.cookie);
                    localStorage.setItem('token',md5(md5(token)));
                    this.$router.push('/home/task');
                }
            });
        }
    }
}
</script>
<style scoped lang="less">
@import './style.less';
</style>